package com.xxx.video.mine.activitys;

import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;


import com.xxx.video.R;
import com.xxx.video.commen.activitys.BaseActivity;
import com.xxx.video.commen.utils.FontCacheUtils;
import com.xxx.video.commen.utils.StatusBarUtil;
import com.xxx.video.commen.utils.StringUtils;
import com.xxx.video.commen.utils.ToastUtils;
import com.xxx.video.commen.views.FontTextView;
import com.xxx.video.mine.presenters.ChangeMobileOrEmailPresenter;
import com.xxx.video.mine.presenters.IChangeMobileOrEmailView;

import butterknife.BindView;
import butterknife.OnClick;

public class ChangeMobileOrEmailActivity extends BaseActivity<ChangeMobileOrEmailPresenter> implements IChangeMobileOrEmailView {
    public static int CHANGE_MOBILE = 301;
    public static int CHANGE_EMAIL = 302;
    public static int CHANGE_NICK_NAME = 303;

    @BindView(R.id.et_change_mobile_email_activity_content)
    EditText etChangeMobileEmailActivityContent;
    /**
     * page type
     */
    private int mType;
    /**
     * last page content
     */
    private String mContent;

    @Override
    public void initToolbarData() {
        super.initToolbarData();
        showActionBar();
        StatusBarUtil.getInstance().setStatusBarTransparent(this, true);
        setIsShowActionbarLine(true);
        Typeface customFont = FontCacheUtils.getInstance().getTypeface(FontTextView.ttf3, this);
        etChangeMobileEmailActivityContent.setTypeface(customFont);
    }

    @Override
    protected ChangeMobileOrEmailPresenter createPresenter() {
        return new ChangeMobileOrEmailPresenter(this, this);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_change_mobile_email;
    }

    @Override
    public void initData(Bundle extras) {
        showLayoutStatus(1);
        if (extras != null) {
            mType = extras.getInt("Type", CHANGE_MOBILE);
            mContent = extras.getString("Content", "");
        }
        etChangeMobileEmailActivityContent.setText(mContent);
        if (mType == CHANGE_MOBILE) {
            setActionBarTitle(R.string.title_change_mobile_activity);
            etChangeMobileEmailActivityContent.setHint(R.string.et_change_mobile_activity_content_hint);
        } else if (mType == CHANGE_EMAIL) {
            setActionBarTitle(StringUtils.getInstance().getString(R.string.title_change_email_activity));
            etChangeMobileEmailActivityContent.setHint(StringUtils.getInstance().getString(R.string.et_change_email_activity_content_hint));
        } else if (mType == CHANGE_NICK_NAME) {
            setActionBarTitle(R.string.title_change_nick_name_activity);
            etChangeMobileEmailActivityContent.setHint(R.string.et_change_nick_name_activity_content_hint);
        }
    }

    @Override
    public void showRootLayoutStatus(int status) {
        showLayoutStatus(status);
    }


    @OnClick({R.id.tv_change_mobile_email_activity_save})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_change_mobile_email_activity_save:
                getPresenter().saveUserInfo(mType);
                break;
            default:
                break;
        }
    }

    @Override
    public String getEmailOrMobile() {
        return etChangeMobileEmailActivityContent.getText().toString().trim();
    }

    @Override
    public void upDateUserInfoSuccess() {
        /*
         * update user info
         */
        if (mType == CHANGE_MOBILE) {
            ToastUtils.showSuccess(StringUtils.getInstance().getString(R.string.tip_update_mobile_success));
        } else if (mType == CHANGE_EMAIL) {
            ToastUtils.showSuccess(StringUtils.getInstance().getString(R.string.tip_update_email_success));
        } else if (mType == CHANGE_NICK_NAME) {
            ToastUtils.showSuccess(StringUtils.getInstance().getString(R.string.tip_update_nick_name_success));
        }
        finish();
    }
}
